package org.wlldTest.lesson11;


import org.dromara.easyai.matrixTools.Matrix;
import org.dromara.easyai.tools.Knn;

import java.util.Random;

public class Test {
    public static void main(String[] args) throws Exception {
        test();
    }

    public static Matrix getFeature(float x, float y) throws Exception {
        Matrix matrix = new Matrix(1, 2);
        matrix.setNub(0, 0, x);
        matrix.setNub(0, 1, y);
        return matrix;
    }

    public static void test() throws Exception {
        Knn knn = new Knn(5);
        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            float x1 = random.nextFloat();
            float y1 = random.nextFloat();
            float x2 = x1 + 2;
            float y2 = y1 + 2;
            float x3 = x1 + 5;
            float y3 = y1 + 5;
            Matrix feature1 = getFeature(x1, y1);
            Matrix feature2 = getFeature(x2, y2);
            Matrix feature3 = getFeature(x3, y3);
            knn.insertMatrix(feature1, 1);
            knn.insertMatrix(feature2, 2);
            knn.insertMatrix(feature3, 3);
        }
        float x1 = random.nextFloat();
        float y1 = random.nextFloat();
        float x2 = x1 + 2;
        float y2 = y1 + 2;
        float x3 = x1 + 5;
        float y3 = y1 + 5;
        Matrix feature1 = getFeature(x1, y1);
        Matrix feature2 = getFeature(x2, y2);
        Matrix feature3 = getFeature(x3, y3);
        int typeID = knn.getType(feature3);
        System.out.println("类别ID：" + typeID);
    }
}
